"""
@name : 作业
@author : FanMY_71
@projectname: Pycharm练习
@Time: 2022/8/12-9:37
"""
# import IPy
# from pythonping import ping
# from multiprocessing import Process
# import netifaces
#
#
# # ping
# def ping_ip(ip):
#     result = ping(ip, timeout=1)
#     if result.success():
#         print(str(ip) + ":" + "up")
#     else:
#         print(str(ip) + ":" + "down")
#
#
# # # ip_net=input("输入网段:")
# tmp = netifaces.ifaddresses('ens33')[netifaces.AF_INET]
# # 获得本机ip地址
# ip = tmp[0]['addr']
# # 获得本机所在网段
# ip_net = '.'.join([ip.split('.')[0], ip.split('.')[1], ip.split('.')[2], '0/24'])
# # 获得网段内所有ip
# ips = IPy.IP(ip_net)
# p_lst = []
# if __name__ == '__main__':
#     for ip in ips:
#         p = Process(target=ping_ip, args=(str(ip),))
#         p_lst.append(p)
#         p.start()
#     for p in p_lst:
#         p.join()
#     print("end...")

import requests
import re

url = "https://www.sanchuangedu.cn"
result = requests.get(url)
print(result.text)
imgs = re.findall(r"(?<=<img src=).*(?= width)", result.text)
print(imgs)

for i in imgs:
    # 请求图的二进制数据
    img = requests.get(url + '/' + i).content
    with open(f"./{i}", "wb") as fp:
        fp.write(img)
        print(i, "下载成功！")